package Model;

import Data.NhanVien;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author bienphongvnn
 */
public class NhanVienModel {

    public static ArrayList<NhanVien> ListNhanVien() {
        ArrayList<NhanVien> ds = new ArrayList<NhanVien>();
        Connection con = ConnectionProvider.Connect();
        try {
            String sql = "SELECT * FROM nhanvien";
            Statement statement = con.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                NhanVien kh = new NhanVien();
                kh.MaNhanVien = rs.getString("MaNhanVien");
                kh.TenNhanVien = rs.getString("TenNhanVien");
                kh.NgaySinh = rs.getDate("NgaySinh");
                kh.GioiTinh = rs.getInt("GioiTinh");
                kh.CMND = rs.getString("CMND");
                kh.DiaChi = rs.getString("DiaChi");
                kh.DienThoai = rs.getString("DienThoai");
                kh.MaBoPhan = rs.getString("MaBoPhan");
                kh.HoaDon_MaHoaDon = rs.getString("HoaDon_MaHoaDon");
                ds.add(kh);
            }
            con.close();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        } finally {

        }
        return ds;
    }

    //Tim kiếm
    public static ArrayList<NhanVien> TimKiemTatCa(String keyword) {
        ArrayList<NhanVien> ds = new ArrayList<NhanVien>();
        Connection conn = ConnectionProvider.Connect();
        try {
            String sql = "Select  * from nhanvien where MaNhanVien = '" + keyword + "'";
            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                NhanVien kh = new NhanVien();
                kh.MaNhanVien = rs.getString("MaNhanVien");
                kh.TenNhanVien = rs.getString("TenNhanVien");
                kh.NgaySinh = rs.getDate("NgaySinh");
                kh.GioiTinh = rs.getInt("GioiTinh");
                kh.CMND = rs.getString("CMND");
                kh.DiaChi = rs.getString("DiaChi");
                kh.DienThoai = rs.getString("DienThoai");
                kh.MaBoPhan = rs.getString("MaBoPhan");
                kh.HoaDon_MaHoaDon = rs.getString("HoaDon_MaHoaDon");
                ds.add(kh);
            }

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        } finally {

        }
        return ds;
    }
}
